  import {
  ClassMode
} from '../../modules/class_mode.js'
import {
  LikeMode
} from '../../modules/like_mode.js'
const classmode = new ClassMode();
const likemode = new LikeMode();
Page({


  /**
   * 页面的初始数据
   */
  data: {
    first: 0,
    last: 1,
    index: 0
  },




  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    classmode._getStorage(this.data.index, (res, resSum) => {
      res.country = "http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4af4b12b3cd9337d5e7&uin=346897220&vkey=6292F51E1E384E061FF02C31F716658E5C81F5594D561F2E88B854E81CAAB7806D5E4F103E55D33C16F3FAC506D1AB172DE8600B37E43FAD&fromtag=46"
      this.setData({
        // ... res,  扩散运算符
        classData: res,
        classDataSum: resSum,
        idDecide: res.artist_id % 3
      })
      // console.log(res)
    })
  },
  // ·····································································
  onLike: function(e) {
    let haveGive = e.detail.havrGive
    likemode.like(haveGive, this.data.classData.area, this.data.classData.country)
  },
  // ······································································
  onRight: function(e) {
    // console.log(e)
    if (this.data.index >= 0 && this.data.index < this.data.classDataSum.length - 2) {
      let i = ++this.data.index
      this.setData({
        first: 1,
        index: i
      })
    }
    if (this.data.index > this.data.classDataSum.length - 3) {
      this.setData({
        last: 0
      })
    }
    this._setClassData()
  },


  onLeft: function() {
    if (this.data.index > 0) {
      let i = --this.data.index
      this.setData({
        last: 1,
        index: i
      })
    }
    if (this.data.index == 0) {
      this.setData({
        first: 0
      })
    }

    this._setClassData()
  },


  _setClassData: function() {
    classmode._getStorage(this.data.index, (res, res2) => {
      this.setData({
        classData: res,
        classDataSum: res2,
        idDecide: res.artist_id % 3
      })
    })
  },




  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})